<?php
class modpicture extends CI_Model{
	var $picture = "gallery_pictures";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_picture,$id_album,$nama_picture,$tgl_picture,$keterangan)
	{
		$this->id_picture= $id_picture;
		$this->id_album= $id_album;
		$this->nama_picture= $nama_picture;
		$this->tgl_picture= $tgl_picture;
		$this->keterangan= $keterangan;
	}
	
	function getList($id_album,$page){
		$this->db->select('*');
		$this->db->from('gallery_pictures');
		$this->db->where('id_album', $id_album);
		$this->db->limit($page); 
		$query = $this->db->get();
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{		
		$arrayData = array(
			'id_picture'=>$this->id_picture,
			'id_album'=>$this->id_album,
			'nama_picture'=>$this->nama_picture,
			'tgl_picture'=>$this->tgl_picture,
			'keterangan'=>$this->keterangan
		);
		return $this->db->insert($this->picture, $arrayData);
	}
	
	function update($id_picture)
	{
		$arrayData = array(
			'id_album'=>$this->id_album,
			'nama_picture'=>$this->nama_picture,
			'tgl_picture'=>$this->tgl_picture,
			'keterangan'=>$this->keterangan
		);
		$this->db->where('id_picture', $id_picture);
		return $this->db->update($this->picture, $arrayData);
	}
        
	function remove($id_picture)
	{
		$this->db->where('id_picture', $id_picture);
		return $this->db->delete($this->picture);
	}	
	
	function detail($id_picture)
	{
		$this->db->where('id_picture', $id_picture);
		$query = $this->db->get($this->picture);	
		return $query->result_array();
	}
	
	function getListSearch($name){
		$this->db->like('nama_picture',$name);
		$query = $this->db->get($this->picture);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getImgDetail($id_album)
	{
		$this->db->select('*');
		$this->db->from('gallery_pictures');
		$this->db->join('gallery_album', 'gallery_album.id_album = gallery_pictures.id_album', 'left');
		$this->db->where('gallery_pictures.id_album', $id_album);
		$query = $this->db->get();	
		return $query->result_array();
	}
	
}
?>